// pages/teamto/teamto.js
import { getTeamList } from '../../config/https';   //我的团队

const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    page:0,
    teamtype:'',   //判断是一级会员还是二级会员
    loadMore: false, //加载中提示
    finished: false, //是否已经请求完全部数据
    list: [],     //数据
    num:'', 
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      teamtype: options.teamtype
    })
    this.onList()
  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },
  onList(){
    var that = this
    that.setData({
      loadMore: true
    })
    getTeamList({
      page:++this.data.page,
      team_type: this.data.teamtype
    }).then(res=>{
      console.log(res)
      var list = res.team
      list = that.data.list.concat(list)
      that.setData({
        loadMore: false
      })
      if (list.length == 0) {
      } else {
        that.setData({
          finished: res.team.length < res.pagesize ? true : false
        })
      }
      wx.stopPullDownRefresh();
      that.setData({
        list,
        num: that.data.teamtype == 'one' ? res.team_num.one_count : res.team_num.two_count
      })
    
    }).catch(err=>{
      console.log(res)
    })
    
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if (!this.data.finished && !this.data.loadMore) {
      this.onHostList()
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})